﻿Public Class clsDbBsiteMess
    Public Function GetErrorList(ByVal szIP As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT err_code1 AS 結果コード, err_mess1 as 結果内容 "
        szSql &= "  FROM KAD.t_bsite_mess_tbl "
        szSql &= "WHERE ipadrs = '" & szIP & "'  and err_code1<>'' and err_mess1<>''  "
        Dim i As Integer
        For i = 2 To 10
            szSql &= "UNION ALL "
            szSql &= String.Format("SELECT err_code{0} AS エラーコード, err_mess{0} as エラー内容 ", i)
            szSql &= "  FROM KAD.t_bsite_mess_tbl "
            szSql &= "WHERE ipadrs = '" & szIP & "'  and err_code1<>'' and err_mess1<>'' "
        Next

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szIP)
        If IsNothing(dt) Then
            GetErrorList = New DataTable
        Else
            GetErrorList = dt
        End If
    End Function

    Public Function CheckOnHold(ByVal szIP As String) As Boolean
        Dim szSql As String = ""
        szSql &= "SELECT err_code1, err_mess1 "
        szSql &= "  FROM KAD.t_bsite_mess_tbl "
        szSql &= "WHERE ipadrs = '" & szIP & "' "
        szSql &= String.Format("AND (err_code1 LIKE '{0}%' OR err_code1 LIKE '{1}%') ", _
                                frmBsiteResult.HOLD_STRING1, frmBsiteResult.HOLD_STRING2)
        Dim i As Integer
        For i = 2 To 10
            szSql &= "UNION ALL "
            szSql &= String.Format("SELECT err_code{0} AS エラーコード, err_mess{0} as エラー内容 ", i)
            szSql &= "  FROM KAD.t_bsite_mess_tbl "
            szSql &= "WHERE ipadrs = '" & szIP & "' "
            szSql &= String.Format("AND (err_code{0} LIKE '{1}%' OR err_code{0} LIKE '{2}%') ", _
                                    i, frmBsiteResult.HOLD_STRING1, frmBsiteResult.HOLD_STRING2)
        Next

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, szIP)
        If IsNothing(dt) Then
            CheckOnHold = False
        Else
            If dt.Rows.Count > 0 Then
                CheckOnHold = True
            Else
                CheckOnHold = False
            End If
        End If
    End Function
End Class
